package com.jiaai.web.zfp_back.system;


import com.alibaba.dubbo.config.annotation.Reference;

import com.alibaba.fastjson.JSONArray;
import com.jiaai.advertisement_model.api.TAdvertisementApi;
import com.jiaai.advertisement_model.model.VAdvertisement;
import com.jiaai.util.RestResultGenerator;
import org.springframework.web.bind.annotation.*;

/**
 * class_name:AdvertisementControll
 * describe:TODO
 * create_user:张昉平
 * create_date:2017/12/20
 * create_date:17:23
 */
@RestController
@RequestMapping("/api/v1/admin/advertisement")
public class AdvertisementControll {

    @Reference(check = false)
    private TAdvertisementApi advertisementApi;

    @PostMapping("/addOrUpAdvertisement")
    public Object addOrUpAdvertisement(@RequestBody VAdvertisement vAdvertisement)throws Exception{
        return RestResultGenerator.genSuccessResult(advertisementApi.addOrUpAdvertisement(vAdvertisement));
    }

    @PostMapping("/deleteAdvertisement/{id}")
    public Object deleteAdvertisementv(@PathVariable("id") Integer id)throws Exception{
        return RestResultGenerator.genSuccessResult(advertisementApi.deleteAdvertisement(id));
    }

    @GetMapping("/selectAdvertisement")
    public Object selectAdvertisement()throws Exception{
        Object obj = advertisementApi.selectAdvertisement();
        return RestResultGenerator.genSuccessResult(JSONArray.parseArray((String)obj));
    }

    @GetMapping("/selectById/{id}")
    public Object selectEvAdvertisement(@PathVariable("id") Integer id)throws Exception{
        return RestResultGenerator.genSuccessResult(advertisementApi.selectById(id));
    }
}
